package com.example.wallpaperapp.ui.activity;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.example.wallpaperapp.R;
import com.example.wallpaperapp.adapter.FindFragmentListAdapter;
import com.example.wallpaperapp.adapter.MainpagerAdapter;
import com.example.wallpaperapp.base.BaseActivity;
import com.example.wallpaperapp.bean.FindPreviewBean;
import com.example.wallpaperapp.bean.HomeImageRecyclerViewBean;
import com.example.wallpaperapp.bean.Moment;
import com.example.wallpaperapp.utils.RecyclerViewSpacesItemDecoration;
import com.example.wallpaperapp.utils.ToastUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cn.bingoogolapple.baseadapter.BGAOnRVItemClickListener;
import cn.bingoogolapple.baseadapter.BGAOnRVItemLongClickListener;
import cn.bingoogolapple.photopicker.imageloader.BGARVOnScrollListener;
import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;

import static com.mob.MobSDK.getContext;

public class MainPagerActivity extends BaseActivity implements BGANinePhotoLayout.Delegate, BGAOnRVItemClickListener, BGAOnRVItemLongClickListener {

    private RecyclerView mMomentRv;
    private MainpagerAdapter mainpagerAdapter;
    private BGANinePhotoLayout mCurrentClickNpl;
    List<Moment> moments;

    protected void initView(View view) {
        mMomentRv = view.findViewById(R.id.rv_mainpager_list_moments);
//        mainpagerAdapter = new MainpagerAdapter(mMomentRv,context);
        mMomentRv.addOnScrollListener(new BGARVOnScrollListener(getActivity()));
        mMomentRv.setLayoutManager(new LinearLayoutManager(getActivity()));
        mainpagerAdapter.setOnRVItemClickListener(this);
        mainpagerAdapter.setOnRVItemLongClickListener(this);
        mMomentRv.addItemDecoration(new RecyclerViewSpacesItemDecoration(RecyclerViewSpacesItemDecoration.TOP_DECORATION, 40));
        mMomentRv.setAdapter(mainpagerAdapter);
        addNetImageTestData();
    }

    private Activity getActivity() {
        return null;
    }

    /**
     * 添加网络图片测试数据
     */
    private void addNetImageTestData() {
        moments = new ArrayList<>();
        moments.add(new Moment("寄生虫专家", new ArrayList<>(Arrays.asList("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1606121581344&di=c13c50e2e0b15e62be2eacb306abc282&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201811%2F29%2F20181129150258_8l4QK.thumb.700_0.jpeg")), "1"));
        moments.add(new Moment("寄生虫超级专家", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603697069543&di=52ea9deab5e252f7003b54c691d159e7&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F64%2F52%2F01300000407527124482522224765.jpg", "1张网络图片", new ArrayList<>(Arrays.asList("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603697069543&di=52ea9deab5e252f7003b54c691d159e7&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F64%2F52%2F01300000407527124482522224765.jpg")), "1", "2", 1));
        moments.add(new Moment("寄生虫超级无敌专家", new ArrayList<>(Arrays.asList("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered2.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered3.png"))));
        moments.add(new Moment("寄生虫砖家", new ArrayList<>(Arrays.asList("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered11.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered12.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered13.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered14.png", "http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered15.png"))));
        ArrayList<String> photos = new ArrayList<>();
        for (int i = 1; i < 20; i++) {
            photos.add("http://bgashare.bingoogolapple.cn/refreshlayout/images/staggered" + i + ".png");
        }
        moments.add(new Moment("寄生虫研究院", photos));
        mainpagerAdapter.setData(moments);
    }


    @Override
    public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
        mCurrentClickNpl = ninePhotoLayout;
    }

    @Override
    public void onClickExpand(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
        ninePhotoLayout.setIsExpand(true);
        ninePhotoLayout.flushItems();
    }

    //item的点击事件 跳转到图片预览界面
    @Override
    public void onRVItemClick(ViewGroup parent, View itemView, int position) {
        ToastUtil.makeText(this, "点击了" + position);

        //临时测试传输图片集合  后期传输一系列数据
        FindPreviewActivity.startFindPreviewActivity(this, new FindPreviewBean(moments.get(position).photos));

    }

    @Override
    public boolean onRVItemLongClick(ViewGroup parent, View itemView, int position) {
        return false;
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_main_pager;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {

    }

}